var express = require('express');
var jwt = require('jsonwebtoken')
var router = express.Router();
var { fzliaotianModel,appliaotianModel,userModel,landlordModel,} = require('../model/model')
// const { Server } = require("socket.io");

/* GET home page. */
// router.get('/', function (req, res, next) {
//   res.render('index', { title: 'Express' });
// });

// 添加与房主的聊天记录
router.post('/fzadd', async (req, res) => {
  fzliaotianModel.create(req.body)
    res.send({
      code: 200,
      msg: '添加成功'
    })
  
})

// 添加与客服的聊天记录
router.post('/appadd', async (req, res) => {
  appliaotianModel.create(req.body)
    res.send({
      code: 200,
      msg: '添加成功'
    })
})

// 获取与房主的聊天记录
router.get('/fzget', async (req, res) => {
  // console.log(111222333);
  // let fls = req.query
  let fdata = await fzliaotianModel.find().populate('lid')
    res.send({
      code: 200,
      msg: '查询成功',
      fdata
    })
    console.log(fdata);
})

// 获取与客服的聊天记录
router.get('/appget', async (req, res) => {
  let als = req.query
  let adata = await appliaotianModel.find(
    {
      $or:[
        {meaname: als.meaname,youaname: als.youaname},
        {meaname: als.youaname,youaname: als.meaname}
      ]
    })
    res.send({
      code: 200,
      msg: '查询成功',
      adata
    })
})

// 消息首页与多房主用户聊天界面渲染
router.get('/fzgetone', async (req, res) => {
  // let fzid = req.query.fzid
  let fzdata = await userModel.find().populate('fid').populate('lid')
  res.send({
    code: 200,
    msg: '查询成功',
    fzdata
  })
})

// 添加多房主用户聊天
router.post('/fzadduser', async (req, res) => {
  userModel.create(req.body)
    res.send({
      code: 200,
      msg: '房主添加成功'
    })
})





module.exports = router;
